package com.xieyong.mywebsite.model.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private String code;
    private String msg;
    private T data;

    public static <E> Result<E> success() {
        Result<E> result = new Result<>();
        result.setCode("200");
        result.setMsg("请求成功");
        return result;
    }

    public static <E> Result<E> success(E data) {
        Result<E> result = new Result<>();
        result.setCode("200");
        result.setMsg("请求成功");
        result.setData(data);
        return result;
    }

    public static <E> Result<E> error(String msg) {
        Result<E> result = new Result<>();
        result.setCode("500");
        result.setMsg(msg);
        return result;
    }

    public static <E> Result<E> error(String code, String msg) {
        Result<E> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
